#include "gui/supplierviewdetailsdialog.h"
#include "gui/separatorwidget.h"
#include "core/constants.h"

void SupplierViewDetailsDialog::initUiComponents()
{
    mainLayout = new QVBoxLayout;
    gridLayout = new QGridLayout;

    nameLabel = new QLabel;
    QFont font = nameLabel->font();

    font.setPointSize(font.pointSize() + 3);
    font.setBold(true);

    font.setPointSize(font.pointSize() + HEADER_UPSIZE);

    nameLabel->setFont(font);
    mainLayout->addWidget(nameLabel);
    mainLayout->addWidget(new SeparatorWidget);

    countryLabel = new QLabel;
    QFont countryFont = countryLabel->font();  // This will be the font for country of origin and contact number
    countryFont.setBold(true);
    countryLabel->setFont(countryFont);
    countryLabel->setText("Country of Origin:");
    gridLayout->addWidget(countryLabel, 1, 0);

    supplierCountryLabel = new QLabel;
    gridLayout->addWidget(supplierCountryLabel, 1, 1);

    contactLabel = new QLabel;
    contactLabel->setFont(countryFont);
    contactLabel->setText("Contact Number:");
    gridLayout->addWidget(contactLabel, 2, 0);

    supplierContactLabel = new QLabel;
    gridLayout->addWidget(supplierContactLabel, 2, 1);

    mainLayout->addLayout(gridLayout);
    mainLayout->addStretch();

    buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
    buttonBox->addButton("&Edit...", QDialogButtonBox::AcceptRole);
    mainLayout->addWidget(buttonBox);

    this->setLayout(mainLayout);
}

void SupplierViewDetailsDialog::initSignalsAndSlots()
{
    connect(this->buttonBox, SIGNAL(accepted()),
            this, SLOT(accept()));
    connect(this->buttonBox, SIGNAL(rejected()),
            this, SLOT(reject()));
}

void SupplierViewDetailsDialog::setSupplier(SupplierModel *supplier)
{
    this->nameLabel->setText(supplier->getName());
    this->supplierCountryLabel->setText(supplier->getCountry());
    this->supplierContactLabel->setText(supplier->getContactNumber());
}

SupplierViewDetailsDialog::SupplierViewDetailsDialog(QWidget *parent, SupplierModel *supplier) :
    QDialog(parent)
{
    this->setWindowTitle("Supplier Details");

    this->initUiComponents();
    this->initSignalsAndSlots();

    this->setSupplier(supplier);

}
